import basicTypes.C4Constant;
import component.BillingSystemUI;

import Prism.core.Architecture;
import Prism.core.Component;
import Prism.core.Connector;
import Prism.core.Port;
import Prism.core.PrismConstants;
import Prism.extensions.port.ExtensiblePort;
import Prism.extensions.port.distribution.SocketDistribution;

// Billing Terminal Program
// This is used for Billing Assist to print bills and check customers bill
public class BillingClient {

	/**
	 * @param args
	 */
	public static void main(String[] args) {        
        Architecture billingClientArchitecture = new Architecture();
        
        // Create BillingSystemUI Component
    	Component billingSystemUIComponent = new Component();
    	
		// Create BillingSystemUI Component's implementation
		billingSystemUIComponent.setImplementation(new BillingSystemUI());
		
		// Add a port to the BillingSystemUI for sending requests.
		Port billingSystemUIRequestPort = new Port(PrismConstants.REQUEST);
		billingSystemUIComponent.addPort(billingSystemUIRequestPort);
		
		// add BillingSystemUI to c4Architecture
		billingClientArchitecture.add(billingSystemUIComponent);
        
		// Create a connector(BillingSystemConn) for BillingSystem
		Connector billingSystemConnClient = new Connector();

		// Add a port to the BillingSystemConn for receiving requests.
		Port billingSystemConnReplyPort = new Port(PrismConstants.REPLY);
		billingSystemConnClient.addPort(billingSystemConnReplyPort);

		// BillingSystemConn is extensiblePort because a terminal of BillingSystemUI connects billingSystem by network
		ExtensiblePort billingSystemConnRequestPort = new ExtensiblePort (PrismConstants.REQUEST);
		billingSystemConnRequestPort.addDistribution(new SocketDistribution());           
		billingSystemConnClient.addPort(billingSystemConnRequestPort);
		
        // Add the BillingSystemConn to the billingArchitecture
		billingClientArchitecture.add(billingSystemConnClient);
		
		// Weld the GUI request port to the connector reply port.
		billingClientArchitecture.weld(billingSystemUIRequestPort, billingSystemConnReplyPort);

		// Start the architecture.
		billingClientArchitecture.start();

		// Connect the connector request port to the BillingSystem.
        billingSystemConnRequestPort.connect(C4Constant.hostname, C4Constant.billingPort);
		
	}

}
